package com.linkhub.oms.admin.modules.product.excel.listener;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.linkhub.oms.admin.modules.product.excel.dto.LocalProductExcelDataDTO;
import com.linkhub.oms.common.enums.IEnumConvert;
import com.linkhub.oms.common.enums.product.LocalProductCategoryEnum;

import java.util.List;
import java.util.Objects;

/**
 * @Description: LocalProductExcelDataListener
 * @Author: echo
 * @Date: 2024/5/11 16:08
 * @Version: 1.0
 */
public class LocalProductExcelDataListener extends BaseLocalProductExcelDataListener<LocalProductExcelDataDTO> {

    public LocalProductExcelDataListener(List<LocalProductExcelDataDTO> list) {
        super(list);
    }

    public LocalProductExcelDataListener() {
        this(Lists.newArrayList());
        super.inValidDataList = Lists.newArrayList();
        super.skuSets = Sets.newHashSet();
        super.upcSets = Sets.newHashSet();
        super.fnskuSets = Sets.newHashSet();
        super.otherCodeSets = Sets.newHashSet();
    }

    @Override
    protected String getSku(LocalProductExcelDataDTO data) {
        return data.getSku();
    }

    @Override
    protected String getUpc(LocalProductExcelDataDTO data) {
        return data.getUpc();
    }

    @Override
    protected String getFnsku(LocalProductExcelDataDTO data) {
        return data.getFnsku();
    }

    @Override
    protected String getOtherCode(LocalProductExcelDataDTO data) {
        return data.getOtherCode();
    }

    @Override
    protected LocalProductExcelDataDTO convertCellData(LocalProductExcelDataDTO data) {
        Integer categoryCode = data.getCategoryCode();
        if (Objects.isNull(categoryCode)) {
            return data;
        }

        LocalProductCategoryEnum categoryEnum = IEnumConvert.valueOf(String.valueOf(categoryCode), LocalProductCategoryEnum.class);
        if (Objects.nonNull(categoryEnum)) {
            data.setCategoryName(categoryEnum.getEnName());
        }

        return data;

    }

}
